home *** CD-ROM | disk | FTP | other *** search
/ Internet Warrior 1993 July / Internet Warrior No. 1 July 1993 - Austin Code Works.ISO / tcpip / tcp201.spe < prev    next >
Encoding:
Text File  |  1993-04-10  |  19.8 KB  |  602 lines

  1.  
  2.  
  3.  
  4.                          ___________________
  5.                          TCPDRV Version 2.01
  6.  
  7.  
  8.                 Preliminary Specification for a TCP/IP
  9.         Application Binary Interface (ABI) to run over MS-DOS.
  10.  
  11.      Copyright  (c)  1992  by  Peter  R.  Tattam,  University  of
  12.      Tasmania.  Permission is granted to reproduce and distribute
  13.      this document without restriction or fee.  This document may
  14.      be  re-formatted   or   translated,   but   the   functional
  15.      specification of the programming interface described  herein
  16.      may not be  changed without  the author's  permission.   The
  17.      author's  name   and  this   notice  must   appear  on   any
  18.      reproduction of this document.
  19.  
  20.      ____________
  21.      Introduction
  22.  
  23.  
  24.      There has been a need for a standard TCP/IP binary interface
  25.      for the MS-DOS  operating system.   Although there are  many
  26.      proprietary specifications for  such a system,  not one  has
  27.      been accepted as universal.  This specification attempts  to
  28.      address the  major  hurdles facing  applications  developers
  29.      writing  network   applications  using   TCP/IP  on   MS-DOS
  30.      machines.   Some applications  access  the network  via  the
  31.      packet driver specification.  Although this solution  solves
  32.      the problem of the multiplicity  of network hardware, it  is
  33.      unsatisfactory when  more  than one  application  wishes  to
  34.      access the  same network  protocol (TCP/IP)  simultaneously.
  35.      What is  required by  an application  is a  standard way  of
  36.      seeing the TCP/IP layer in a manner similar to the machine's
  37.      file system.  This document provides a possible mechanism to
  38.      provide the TCP/IP  services in any  application running  on
  39.      MS-DOS.
  40.  
  41.      _______________________
  42.      Finding the TCP/IP ABI.
  43.  
  44.  
  45.      The TSR (Terminate and Stay Resident) program can attach  to
  46.      an interrupt vector in the range 60H-7FH in a similar manner
  47.      to a  packet driver.   The  first  instruction of  the  hook
  48.      should be  a JMP  NEAR instruction  and  have after  it  the
  49.      string 'TCP_DRVR'  (for want of  a better name). The  vector
  50.      to attach  to should  be specifyable  since  it may  not  be
  51.      possible to determine if the vector  is free.  Calls to  the
  52.      TSR are made using  the standard 8086/88 software  interrupt
  53.      calls through this vector.
  54.  
  55.      Upon loading the TSR, the  IP address, netmask, gateway  etc
  56.      are determined  by a  suitable method,  either directly,  or
  57.      using RARP or BOOTP.  One  should also be able to pass  this
  58.      information via  the command-line,  or use  the  environment
  59.      variables.  The packet  layer could be any  of a variety  of
  60.      mechanisms.  How this is done  is totally open to  question,
  61.      but the following  information should be  accurate once  the
  62.      ABI is loaded and active.  This specification is to  provide
  63.      the next layer above the packet driver interface.
  64.  
  65.      my IP address
  66.      netmask
  67.  
  68.  
  69.  
  70.      gateway IP address(es)
  71.      domain name server IP address(es)  - available for a  higher
  72.      layer than this driver.
  73.  
  74.      _____________
  75.      General notes
  76.  
  77.  
  78.  
  79.      All calls return
  80.           dl = error code (0 if none) (carry set if <> 0)
  81.      except for the driver existence determination
  82.  
  83.      All handles returned  are a word  value corresponding to  an
  84.      index into a  table or list.  They can be  guaranteed to  be
  85.      unique only, and 0 is allowable. If no handles are available
  86.      then the returned handle of an open call is 0FFFFH.  Handles
  87.      are also reusable. The current implementation of Trumpet TCP
  88.      returns handles in steps of 1   starting at 0.  This can  be
  89.      useful for a general  purpose status program to  interrogate
  90.      the status of TCP connections.
  91.  
  92.  
  93.      Most calls have AL register set to option flags. A  standard
  94.      call has the value 0 and may block the processor.
  95.  
  96.      A timeout  is provided  via DX.    If DX  = FFFFH  then  the
  97.      operation  will  proceed  until  done.    All  timeouts  are
  98.      measured in terms of PC clock ticks (18.2 Hz) A timeout of 0
  99.      specifies a non-blocking call and  will not return an  error
  100.      if operation times out. One can usually use the status  call
  101.      to determine the status of the tcp connection.  The  Trumpet
  102.      TCP implements timeouts.  The following calls may block.
  103.  
  104.           tcp: open, close, send, recv
  105.           udp: recv,     (send blocks only if arp required)
  106.           ip:  recv,     (send blocks only if arp required)
  107.  
  108.      All other calls don't block and do not require a timeout.
  109.  
  110.      If the option flag 128 (80H) is set then an asynchronous i/o
  111.      is done.  On completion of i/o, an event handler is  called.
  112.      Other options  are relevant  to the  call concerned.    Care
  113.      needs to  be taken  in  multi-program environments  such  as
  114.      Windows 3  that the  event-handler address  is valid.  Event
  115.      handlers are assigned by the attach/detach event  operation.
  116.      Implementation of asynchronous i/o is optional.  At  present
  117.      the Trumpet TCP does not implement this function.
  118.  
  119.      All register values  will be preserved  across calls  except
  120.      for those which return values.
  121.  
  122.  
  123.  
  124.      ____________
  125.      Driver hooks
  126.  
  127.  
  128.  
  129.      ___________
  130.      driver_info         determine if  driver  is valid  and  the
  131.  
  132.      functionality of the driver
  133.  
  134.           call
  135.                ah   = 00H
  136.                al   = FFH
  137.  
  138.           return
  139.                al   = FFH     no driver loaded
  140.  
  141.                al   = 0  driver loaded
  142.                dh   = additional functionality flags
  143.                     1    = implements timeouts
  144.                     2    = implements async i/o via events
  145.                ds:si = pointer to "TCP_DRVR"
  146.                es:di     = pointer to driver info
  147.                     (including IP address, net params, etc)
  148.  
  149.           driver_info_rec:
  150.                myip      dword
  151.                netmask   dword
  152.                gateway   dword
  153.                dnsserver dword
  154.                timeserver     dword
  155.                mtu       word
  156.                def_ttl   byte
  157.                def_tos   byte
  158.                tcp_mss   word
  159.                tcp_rwin  word
  160.                debug          word
  161.                domain    string[255]  (db 0,255 dup(0))
  162.  
  163.      _____________
  164.      driver_unload  unload driver from memory.
  165.  
  166.  
  167.           call
  168.                ah   = 01H
  169.           return
  170.                dl   = error code
  171.  
  172.      ___________
  173.      driver_doio         perform driver processing
  174.  
  175.  
  176.                     Will call event handlers as required
  177.                     Must be called regularly to process packets
  178.                     Can be attached to timer interrupt.
  179.                     Care must be taken with reentrancy.
  180.  
  181.           call
  182.                ah   = 02H
  183.           return
  184.                ax   = no. of free pkts on IP input queue
  185.                cx   = no. of free pkts on IP output queue
  186.                dl   = error code
  187.  
  188.  
  189.  
  190.      ____________________
  191.      driver_critical_flag     return the driver's critical flag
  192.  
  193.  
  194.           call
  195.                ah   = 03H
  196.           return
  197.                es:di     = pointer to critical flag byte
  198.                dl   = error code
  199.  
  200.      ________________
  201.      copy driver info         copy the  driver  info  to  a  user
  202.  
  203.      buffer
  204.  
  205.           call
  206.                ah   = 04H
  207.                cx   = size of buffer
  208.                es:di     = pointer to local buffer
  209.           return
  210.                cx   = bytes stored
  211.  
  212.  
  213.  
  214.      _________
  215.      TCP hooks
  216.  
  217.  
  218.      ________
  219.      tcp_open  open an active/passive tcp session
  220.  
  221.  
  222.           call
  223.                ah   = 10H
  224.                al   = option flags
  225.                          0    = normal
  226.                          1    = listener
  227.                          128  =   asynchronous.      Notify    by
  228.      event_call
  229.                bx   = tcp_srce (0 = allocate unused port)
  230.                cx   = tcp_dest (0 = any port when listener)
  231.                dx   = timeout (0 = non-blocking, FFFF = infinite)
  232.                si:di     =  ip_dest   (dword)  (0   =  any   when
  233.      listener)
  234.  
  235.           return
  236.                ax   = local port no.
  237.                bx   = handle
  238.                dl   = error code
  239.                          no_handles
  240.                          timed_out
  241.                          invalid_session
  242.  
  243.      _________
  244.      tcp_close close a tcp session
  245.  
  246.  
  247.           call
  248.                ah   = 11H
  249.                al   = option flags
  250.                          0    = normal
  251.                          1    = abort session
  252.                          128  =   asynchronous.      Notify    by
  253.      event_call
  254.                bx   = handle
  255.                dx   = timeout (0 = non-blocking, FFFF = infinite)
  256.           return
  257.                dl   = error code
  258.                     bad_handle
  259.                     timed_out
  260.                     invalid_session
  261.  
  262.      Note: a session closed with a timeout of 0 will not  release
  263.      the handle.    It must  either  be closed  with  a  non-zero
  264.      timeout.  A non-zero timeout will always release the handle,
  265.      as will an abort option.   A listen for any connection  will
  266.      revert back to an IP address of FFFFFFFF when the connection
  267.      returns back to the listen state.  The handling of  listener
  268.      sessions  may   change   in   the   future   to   accomodate
  269.      compatibility with "socket" implementations.
  270.  
  271.  
  272.  
  273.      _______
  274.      tcp_get   read data into buffer
  275.  
  276.  
  277.           call
  278.                ah   = 12H
  279.                al   = option flags
  280.                          0    = normal (wait till buffer full)
  281.                          1    = get as much as possible & return
  282.                          2    = read to <cr><lf> (don't include)
  283.                          128  =    asynchronous.    Notify     by
  284.      event_call
  285.                bx   = handle
  286.                es:di     = pointer to buffer
  287.                cx   = size of buffer
  288.                dx   = timeout (0 = non-blocking, FFFF = infinite)
  289.           return
  290.                buffer has data transferred to it
  291.                ax   = no. bytes transferred
  292.                dl   = error code
  293.                     bad_handle
  294.                     timed_out
  295.                     invalid_session
  296.                dh   = returned flags
  297.                          2 = <cr><lf> read in option 2
  298.                          8 = urgent data present
  299.  
  300.      _______
  301.      tcp_put   write data to buffer
  302.  
  303.  
  304.           call
  305.                ah   = 13H
  306.                al   = option flags
  307.                          0    =   normal   (wait   till    buffer
  308.      delivered)
  309.                          1    = put as much as possible & return
  310.                          2    = append <cr><lf> to data
  311.                          4    =    push    (wait    till     data
  312.      acknowledged)
  313.                          8    = urgent data
  314.                          128  =   asynchronous.      Notify    by
  315.      event_call
  316.                bx   = handle
  317.                es:di     = pointer to buffer
  318.                cx   = size of buffer
  319.                dx   = timeout (0 = non-blocking, FFFF = infinite)
  320.           return
  321.                ax   = no. bytes transferred
  322.                dl   = error code
  323.                     bad_handle
  324.                     timed_out
  325.                     invalid_session
  326.  
  327.      __________
  328.      tcp_status     get status of a TCP session
  329.  
  330.  
  331.           call
  332.                ah   = 14H
  333.                al   = option flags
  334.                          0    = normal
  335.  
  336.  
  337.  
  338.                          128  =   asynchronous.      Notify    by
  339.      event_call
  340.                bx   = handle
  341.           return
  342.                dl   = error code
  343.                     bad_handle
  344.                dh   = tcp_state
  345.                ax   = bytes available for reading
  346.                cx   = bytes still being transmitted
  347.                es:di     = pointer to session info
  348.                          ip_srce   dword
  349.                          ip_dest   dword
  350.                          ip_prot   byte
  351.                          active    byte  (> 0 is active)
  352.  
  353.  
  354.  
  355.      _________
  356.      UDP Hooks
  357.  
  358.  
  359.  
  360.      ________
  361.      udp_open
  362.  
  363.           call
  364.                ah   = 20H
  365.                al   = option flags
  366.                          0    = normal
  367.                          128  =   asynchronous.      Notify    by
  368.      event_call
  369.                bx   = udp_srce     (0 = allocate next unused)
  370.                cx   = udp_dest     (0 = listen for any)
  371.                si:di     = ip_dest (0/FFFFFFFF = listen for any)
  372.           return
  373.                ax   = local port no.
  374.                bx   = handle
  375.                dl   = error code
  376.                     no_handles
  377.      _________
  378.      udp_close
  379.  
  380.           call
  381.                ah   = 21H
  382.                al   = option flags
  383.                          0    = normal
  384.                          128  =   asynchronous.      Notify    by
  385.      event_call
  386.                bx   = handle
  387.           return
  388.                dl   = error code
  389.                     bad_handle
  390.  
  391.      ________
  392.      udp_recv
  393.  
  394.           call
  395.                ah   = 22H
  396.                al   = option flags
  397.                          0    = normal
  398.                          128  =  asynchronous   i/o  signal   via
  399.      event_call
  400.                bx   = handle
  401.                es:di     = pointer to buffer
  402.                cx   = length
  403.                dx   = timeout (FFFF = infinite)
  404.           return
  405.                ax   = no. bytes transferred
  406.                dl   = error code
  407.                     bad_handle
  408.                     timed_out
  409.                bp   = ttl & tos  (ttl = lo byte, tos = hi byte)
  410.                          0 = default ttl & tos
  411.                si   = id
  412.      (note that the IP address of the most recent packet read  is
  413.      available with a status call, if receiving all)
  414.  
  415.      ________
  416.      udp_send
  417.  
  418.           call
  419.                ah   = 23H
  420.  
  421.  
  422.  
  423.                al   = option flags
  424.                          0    = normal
  425.                          128  =  asynchronous   i/o  signal   via
  426.      event_call
  427.                bx   = handle
  428.                es:di     = pointer to buffer
  429.                cx   = length
  430.                bp   = ttl & tos  (ttl = lo byte, tos = hi byte)
  431.                       0 = default ttl & tos
  432.                si   = id
  433.  
  434.           return
  435.                ax   = no. bytes transferred
  436.                dl   = error code
  437.                     bad_handle
  438.  
  439.  
  440.      __________
  441.      udp_status
  442.  
  443.           call
  444.                ah   = 24H
  445.                al   = option flags
  446.                          0    = normal
  447.                          128  =   asynchronous.      Notify    by
  448.      event_call
  449.           return
  450.                ax   = number of packets available
  451.                cx   = size of next packet (0 if none)
  452.                dl   = error code
  453.                     bad_handle
  454.                es:di     = pointer to session info
  455.                          ip_srce   dword
  456.                          ip_dest   dword
  457.                          ip_prot   byte
  458.                          active    byte  (> 0 is active)
  459.  
  460.  
  461.  
  462.      ________
  463.      IP Hooks
  464.  
  465.      _______
  466.      ip_open
  467.  
  468.           call
  469.                ah   = 30H
  470.                al   = option flags
  471.                          0    = normal
  472.                          128  =   asynchronous.      Notify    by
  473.      event_call
  474.                bl   = protocol
  475.                si:di     = ip_dest (0/FFFFFFFF = listen for any)
  476.           return
  477.                ax   = handle
  478.                dl   = error code
  479.                     no_handles
  480.  
  481.      ________
  482.      ip_close
  483.  
  484.           call
  485.                ah   = 31H
  486.                bx   = handle
  487.           return
  488.                dl   = error code
  489.                     bad_handle
  490.  
  491.      _______
  492.      ip_recv
  493.  
  494.           call
  495.                ah   = 32H
  496.                al   = option flags
  497.                          0    = normal
  498.                          128  =  asynchronous   i/o  signal   via
  499.      event_call
  500.                bx   = handle
  501.                es:di     = pointer to buffer
  502.                cx   = length
  503.                dx   = timeout (FFFF = infinite)
  504.           return
  505.                ax   = no. bytes transferred
  506.                dl   = error code
  507.                     bad_handle
  508.                     timed_out
  509.                bp   = ttl & tos  (ttl = lo byte, tos = hi byte)
  510.                          0 = default ttl & tos
  511.                si   = id
  512.  
  513.      (note that the IP address of the most recent packet read  is
  514.      available with a status call, if receiving all)
  515.  
  516.      _______
  517.      ip_send
  518.  
  519.           call
  520.                ah   = 33H
  521.                al   = option flags
  522.                          0    = normal
  523.                          128  =  asynchronous   i/o  signal   via
  524.      event_call
  525.                bx   = handle
  526.                es:di     = pointer to buffer
  527.  
  528.  
  529.  
  530.                cx   = length
  531.                bp   = ttl & tos  (ttl = lo byte, tos = hi byte)
  532.                       0 = default ttl & tos
  533.                si   = id
  534.  
  535.           return
  536.                ax   = no. bytes transferred
  537.                dl   = error code
  538.                     bad_handle
  539.  
  540.      _________
  541.      ip_status
  542.  
  543.           call
  544.                ah   = 34H
  545.                al   = option flags
  546.                          0    = normal
  547.                          128  =   asynchronous.      Notify    by
  548.      event_call
  549.           return
  550.                ax   = number of packets available
  551.                cx   = size of next packet (0 if none)
  552.                dl   = error code
  553.                     bad_handle
  554.                es:di     = pointer to session info
  555.                          ip_srce   dword
  556.                          ip_dest   dword
  557.                          ip_prot   byte
  558.                          active    byte  (> 0 is active)
  559.  
  560.  
  561.  
  562.      _________________________
  563.      Event handlers (optional)
  564.  
  565.  
  566.      All registers  are saved  before event  handler called,  and
  567.      restored after event handler done.  Information returned  is
  568.      call dependent.  Note that DS  undefined, so that it is  the
  569.      users responsibility to set up the called environment.  Note
  570.      also that  Windows  3.0  has to  be  managed  suitably  when
  571.      performing up-calls asynchronously.
  572.  
  573.      ___________________
  574.      Attach_event_global
  575.  
  576.  
  577.           allow chaining, but check for duplicates
  578.  
  579.           call
  580.                ax   = 4000H
  581.                es:di     = address of event handler upcall
  582.           return
  583.                dl   = error code
  584.                     already_attached
  585.  
  586.      ___________________
  587.      Detach_event_global
  588.  
  589.  
  590.           call
  591.                ax   = 4100H
  592.                es:di     = address of event handler upcall
  593.           return
  594.                dl   = error code
  595.                     not_attached
  596.  
  597.      __________________
  598.      Attach_event_local
  599.  
  600.  
  601.           no chaining allowed, only 1 per handle
  602.  
  603.           call
  604.                ax   = 4200H
  605.                bx   = handle
  606.                es:di     = address of event handler upcall
  607.           return
  608.                dl   = error code
  609.                     bad_handle
  610.                     already_attached
  611.      __________________
  612.      Detach_event_local
  613.  
  614.  
  615.           call
  616.                ax   = 4300H
  617.                bx   = handle
  618.           return
  619.                dl   = error code
  620.                     bad_handle
  621.                     not_attached
  622.      __________
  623.      event_call
  624.  
  625.  
  626.           upcall
  627.  
  628.  
  629.  
  630.                ax   = event-id   (ah  = same  as int  call, al  =
  631.      subfunction)
  632.                bx   = handle (FFFF if general failure)
  633.                cx:dx     = info  (e.g. no of bytes transferred)
  634.  
  635.           return
  636.                registers not preserved
  637.  
  638.  
  639.      ___________
  640.      Error Codes
  641.  
  642.  
  643.           no_error              = 0;
  644.            err_badcall           = 1;
  645.            err_critical          = 2;
  646.            err_nohandles         = 3;
  647.            err_badhandle         = 4;
  648.            err_timeout           = 5;
  649.            err_badsession        = 6;
  650.